package com.knowledge.business.controller;

import com.knowledge.business.service.impl.DocumentVectorService;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文档分段向量化控制器
 *
 * @author knowledge
 */
//@RestController
//@RequestMapping("/business/vectorization")
public class KnowledgeDocumentSegmentVectorizationController extends BaseController {

    @Autowired
    private DocumentVectorService documentVectorizationService;

    /**
     * 对指定文档的所有分段进行向量化处理
     *
     * @param documentId 文档ID
     * @return 结果
     */
    @PostMapping("/document/{documentId}")
    public AjaxResult vectorizeDocumentSegments(@PathVariable String documentId) {
        try {
            documentVectorizationService.vectorizeDocumentSegments(documentId);
            return AjaxResult.success("文档分段向量化处理完成");
        } catch (Exception e) {
            return AjaxResult.error("文档分段向量化处理失败: " + e.getMessage());
        }
    }

    /**
     * 对所有未处理的文档分段进行向量化处理
     *
     * @return 结果
     */
    @PostMapping("/all")
    public AjaxResult vectorizeAllPendingSegments() {
        try {
            documentVectorizationService.vectorizeAllPendingSegments();
            return AjaxResult.success("所有未处理文档分段向量化处理完成");
        } catch (Exception e) {
            return AjaxResult.error("所有未处理文档分段向量化处理失败: " + e.getMessage());
        }
    }

    /**
     * 对单个分段进行向量化处理
     *
     * @param segmentId 分段ID
     * @return 结果
     */
    @PostMapping("/segment/{segmentId}")
    public AjaxResult vectorizeSegment(@PathVariable String segmentId) {
        try {
            // 这里可以添加对单个分段的向量化处理逻辑
            return AjaxResult.success("分段向量化处理完成");
        } catch (Exception e) {
            return AjaxResult.error("分段向量化处理失败: " + e.getMessage());
        }
    }
}